﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lyh.Train.Data;
using System.Net;

namespace Lyh.Train.Common.Http
{
    public class LoginHelper
    {
        public static bool Login(string userName, string pwd, string randCode, ref string msg)
        {
            HttpClient httpClient = new HttpClient(Context.Cookies);
            if (Context.Proxy != "")
            {
                httpClient.Proxy = new WebProxy(Context.Proxy);
            }
            string data = string.Format("loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}", userName, pwd, randCode);
            string text = httpClient.Post(Context.LoginUrl, data, Context.Host, Context.Origin, Context.LoginReferer, Context.HttpMethodPost);
            text = text.Replace("\"", "");
            bool flag = text.Contains("loginCheck:Y");
            if (!flag)
            {
                msg = HtmlHelper.GetContent(text, "messages:", "],").Replace("[", "").Replace("]", "");
            }
            return flag;
        }
    }
}
